﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title></title>
	<script type="text/javascript">
		document.domain = "wanpijie.com";
		var allowExtension = ".jpg&.jpeg&.gif&.bmp&.png&";
		var queryString = {};
		var collection = {
			dictionary: function (source, separator) {
				if (!separator) separator = "&";
				var array = source.split(separator);
				var temp = [];
				for (var i in array) {
					temp = array[i].split('=');
					this[temp[0]] = temp[1];
				}
			}
		};

		window.onload = function () {
			(function (search) {
				if (search) {
					collection.dictionary.call(this, search.substr(search.indexOf("?") + 1));
				}
			}).apply(this.queryString, [window.location.search]);
			var form = $('f');
			form.action = '/AvatarControl/TransferHandler.ashx?b=' + this.queryString['b'] + "&action=" + this.queryString['action'] + "&signature=" + this.queryString['signature'];
		};

		function uploadToServer(file) {
			if (this.validate(file)) {
				window.document.forms[0].submit();
			}
		}

		function $(id) {
			return document.getElementById(id);
		}

		function validate(file) {
			var extensionIndex = file.value.lastIndexOf(".");
			var extension = file.value.substr(extensionIndex).toLowerCase();
			if (extension.length <= 1 || allowExtension.indexOf(extension + "&") == -1) {
				alert("仅支持上传图片文件");
				return false;
			}
			return true;
		}

		function selectFile() {
			var uploadControl = $("imageFile");
			if (uploadControl.click) {
				uploadControl.click();
			}
		}
	</script>
</head>
<body>
	<form id="f" action="" method="post" enctype="multipart/form-data" name="avatarUpload">
	<input type="file" id="imageFile" name="imageFile" onchange="uploadToServer(this);" accept="image/jpeg, image/png" />
	</form>
</body>
</html>
